from unittest import TestCase as TestCase2

from django.test import TestCase, Client

from .models import Person


class PersonTestCase(TestCase):
    def setUp(self):
        """
        生命周期钩子
        :return:
        """
        Person.objects.create(first_name='fang', last_name='marvin', age=11)
        Person.objects.create(first_name='fang', last_name='ma2', age=11)
        print('setup finished')

    def test_person_can_stand_up(self):
        marvin = Person.objects.get(last_name='marvin')
        ma2 = Person.objects.get(last_name='ma2')
        self.assertEqual('marvin can stand up!', marvin.stand_up())
        self.assertEqual('ma2 can stand up!', ma2.stand_up())

    def test_raise_exception(self):
        with self.assertRaises(Exception):
            raise Exception('some exception')


class ClientTestCase(TestCase):
    def setUp(self):
        self.client = Client()

    def test_client(self):
        response = self.client.get('/demo/')
        print(response.content)
        response = self.client.get('/demo/tax-information/')
        print(response.json()['tax'])


class TestUnitTestTestCase(TestCase2):
    def test(self):
        print('test haaa----------------------------------')
